"===========================
"  文件设置
"===========================
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,cp936
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set autoread         "设置当文件在外部被修改，自动更新该文件

"vim提示信息乱码的解决
language messages zh_CN.utf-8

set nobackup        " 不要备份
set noundofile      " 不生成undo文件
set nowritebackup
set nowrap
set foldmethod=indent
"set foldlevel=999999

set tabstop=2
"set softtabstop=4
set expandtab "把插入的 tab 字符替换成特定数目的空格。具体空格数目跟 tabstop 选项值有关
set shiftwidth=2
au FileType java,php,python,vim,markdown,md,go setl shiftwidth=4
au FileType java,php,python,vim,markdown,md,go setl tabstop=4
set smarttab
set ai "autoindent

"===========================
" keymap设置
"===========================
let mapleader=","

map <leader>sv :source $MYVIMRC<cr>
nmap <leader>ee :e $MYVIMRC<cr>

"leader+h goto head of the line, leader+l goto end of the line
nnoremap <leader>h ^
nnoremap <leader>l $


map <leader>tn :tabnew<cr>
map <leader>tc :tabclose<cr>
map <leader>th :tabp<cr>
map <leader>tl :tabn<cr>

" 移动分割窗口
nmap <C-j> <C-W>j
nmap <C-k> <C-W>k
nmap <C-h> <C-W>h
nmap <C-l> <C-W>l

" 正常模式下 alt+j,k,h,l 调整分割窗口大小
nnoremap <M-j> :resize +5<cr>
nnoremap <M-k> :resize -5<cr>
nnoremap <M-h> :vertical resize -5<cr>
nnoremap <M-l> :vertical resize +5<cr>

" 插入模式移动光标 alt + 方向键
inoremap <M-j> <Down>
inoremap <M-k> <Up>
inoremap <M-h> <left>
inoremap <M-l> <Right>

" IDE like delete
inoremap <C-BS> <Esc>bdei

nnoremap vv ^vg_
" 转换当前行为大写
inoremap <C-u> <esc>mzgUiw`za
" 命令模式下的行首尾
cnoremap <C-a> <home>
cnoremap <C-e> <end>

nnoremap <F2> :setlocal number!<cr>
nnoremap <leader>wr :set wrap!<cr>

" Quickly close the current window
nnoremap <leader>q :q<CR>
" Quickly save the current file
nnoremap <leader>w :w<CR>

" select all
map <leader>sa ggVG"

" 打开当前目录 windows
map <leader>ex :!start explorer %:p:h<CR>

" 打开当前目录CMD
map <leader>cmd :!start<cr>
" 打印当前时间
map <F3> a<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>

" 复制当前文件/路径到剪贴板
nmap ,fn :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
nmap ,fp :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>

"===========================
" 外观/基础设置
"===========================
"set background=light	"light or dark
"colorscheme elflord " 颜色主题
"colorscheme desert " 颜色主题
"colorscheme Tomorrow-Night " 颜色主题

set nu          " 显示行号
set history=500     " 保留历史记录
set backspace=2     " 退格键可用

if has("gui_running")
  " GUI is running or is about to start.
  " Maximize gvim window.
  "set lines=999 columns=999
endif

"===========================
" 插件设置
"===========================
"call plug#begin( '$VIMRUNTIME/plugged' )
call plug#begin( '~/vimfiles/plugged' )
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'vim-airline/vim-airline'
Plug 'fatih/vim-go'
"Plug 'zxqfl/tabnine-vim'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'joshdick/onedark.vim'
Plug 'altercation/vim-colors-solarized'
Plug 'tomasr/molokai'
Plug 'kien/ctrlp.vim'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
if executable('ctags')
    Plug 'majutsushi/tagbar'
endif
call plug#end()

" 颜色主题 colorscheme 设置
"colorscheme onedark
colorscheme solarized
"colorscheme molokai

"NERDTree 设置
"nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <leader>n :NERDTreeToggle<CR>
nnoremap <C-n> :NERDTree<CR>
"nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>

nmap <F9> :TagbarToggle<CR>
let g:tagbar_autofocus = 1

" Start NERDTree and leave the cursor in it.
"autocmd VimEnter * NERDTree | wincmd p

"if exists('g:NERDTreeWinPos')
"    autocmd vimenter * NERDTree D:\workspace
"endif

"===========================
"代码设置
"===========================
"set guifont=Fira\ Code:h10,consolas:h10
"set guifont=consolas:h10 "默认字体大小10
set guifont=Source\ Code\ Pro:h10 "默认字体大小10
"set guifontwide=Fixedsys:h10:cANSI "guifontwide 在windows下好像不可用
syntax enable "打开语法高亮
syntax on "打开语法高亮
set showmatch "设置匹配模式，相当于括号匹配
"set smartindent "智能对齐

au BufRead *.log setf ruby
au BufRead *.conf setf nginx
"au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif


filetype on
filetype plugin indent on

"===========================
"查找/替换相关的设置
"===========================
set hlsearch "高亮显示查找结果
set incsearch "增量查找

" 新文件或读取tpl和dwt后缀的文件时，使用PHP语法高亮
au BufNewFile,BufRead *.tpl,*.dwt setf php
au BufRead *.log,*.conf setf ruby
